//
//  CycleView.m
//  16Practice
//
//  Created by dllo on 16/8/5.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "CycleView.h"

@interface CycleView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;


@end

@implementation CycleView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionView];
    }
    return self;
}

- (void)createCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.pagingEnabled = YES;
    [self addSubview:_collectionView];;
    [_collectionView registerClass:[CycleCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
}

- (void)

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CycleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.picImageView.image = self.array[indexPath.row];
    return cell;
}


@end

@implementation CycleCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _picImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.contentView addSubview:_picImageView];
    }
    return self;
}




@end









